<?php

namespace App\Http\Controllers\admin;

use App\Models\FangOwner;
use App\Models\Notice;
use Illuminate\Http\Request;

class NoticeController extends BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //预约展示页
        $data =Notice::paginate($this->paginate);

        return  view('admin.notice.index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
        $fangowner = FangOwner::select('id','name')->get();

        return view('admin/notice.create',compact('fangowner'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
        $params = $request->except('_token');

        $res = Notice::create($params);

        if($res){
            return  redirect(route('admin.notice.index'));
        }
        return  redirect(route('admin.notice.index'))->withErrors('添加失败');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    public function statusChange(Request $request)
    {
        $paeams = $request->except('_token');


        $res = Notice::where('id',$paeams['id'])->update(['status'=>$paeams['status']]);
        if($res){
            return $this->witeJson(0,null,'修改成功');
        }else{
            return $this->witeJson(0,null,'修改失败');
        }

    }
}
